<?php
	$roomID = $_GET["roomID"];
	$androidID = $_GET["androidID"];
	
	$con = mysql_connect("localhost","root","");
	if (!$con) {
		die('Could not connect: ' . mysql_error());
	}
	
	mysql_select_db("ciu196", $con);
	
	// Check if the room exists
	$sql = "SELECT * from Rooms WHERE roomID = '$roomID';";
	$res = mysql_query($sql,$con);
	if(!$res) {
		die('Error: room already exists' . mysql_error());
	}
	
	$num_rows = mysql_num_rows($res);
	
	// Create new room if it does not exists
	if($num_rows == 0) {		
		$sql = "INSERT INTO Rooms VALUES('$roomID', 'tempo', NULL, NULL);";
		if(!mysql_query($sql,$con)) {
			die('Error: inserting into rooms ' . mysql_error());
		}
			
		$sql = "INSERT INTO OwnersOfRoom VALUES('$androidID', '$roomID');";
		if(!mysql_query($sql,$con)) {
			die('Error: inserting into owners of rooms ' . mysql_error());
		}
		
		echo "Room created";
	} else {
		echo "Room already exists";	
	}
	
	mysql_close($con);	
?>
?>